home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_c / bc4lib.zip / BC40LIB.DOC next >
Text File  |  1994-05-09  |  79KB  |  2,681 lines

  1.                  BC 4.0 Lib
  2.               Borland C/C++ v4.0 Library
  3.                v1.1 (C) Copyright 1994
  4.             Rockland Software Productions
  5.  
  6. Description:
  7.     BC40Lib is a programming library for Borland C/C++ v4.0. It includes
  8.     libraries for mouse, joystick, graphics, math, file I/O, and other 
  9.     miscellaneous functions.
  10.  
  11. Differences between the registered and unregistered versions:
  12.     The unregistered version contains a lib for small memory model. This
  13.     allows you to try the library. The registered version comes with source
  14.     code. Please use the unregistered version for evaluation purposes ONLY.
  15.     If you end up using BC40LIB code, you ARE required to register.
  16.  
  17. Archive contents:
  18.     BC40LIB.doc                      BC40LIB documentation
  19.     *.h                              header files
  20.     *.lib                            library files
  21.     *.c                              source files (registered version only)
  22.     catalog.doc                      Rockland Software Productions catalog
  23.     order.frm                        order form
  24.     support.doc                      support information
  25.     vendor.txt                       distribution policy
  26.  
  27. Installing:
  28.     1. Copy the .lib file(s) to your \bc4\lib directory.
  29.     2. Copy the .h files to \bc4\include directory.
  30.     3. Copy the .c files (registered version only) to your \bc4\source
  31.        directory.
  32.  
  33. Using:
  34.    1. Project options - directories - source directories: add \bc4\source.
  35.    2. Project options - directories - include directories: add \bc4\include.
  36.    3. In each source file that uses a library, be sure to #include the .h
  37.       file.
  38.    4. In the project window, add any included .c or .lib files to the project
  39.       tree.
  40.  
  41. Support:
  42.     Support is available via phone, BBS, email, or mail. See support.doc for
  43.     details.
  44.  
  45. The Library files:
  46.     BC40Lib consists of the following library files:
  47.     Edit - ascii file editor.
  48.     Fileio - text and binary file i/o.
  49.     Generic2 - miscellaneous routines.
  50.     Graf - device independant graphics.
  51.     Joystick - joystick routines.
  52.     Keyboard - interrupt driven keyboard routines.
  53.     Math2 - math routines.
  54.     Mouse - mouse routines.
  55.     Timer - timing routines.
  56.     Help - ascii help file viewer with search and print.
  57.     Getfile - file selection dialog box.
  58.     Each library of routines has a .c or .obj file, and a .h file.
  59.  
  60. A note on color variables:
  61.     Anywhere that the library uses color variables, the allowable values
  62.     are 0-15 or 0-255, depending on the current graphics mode. The values
  63.     correspond to the pallete entries currently in effect. For a default
  64.     CGA thru VGA 16 color palette the values are 0=black, 1=blue, 2=green,
  65.     etc.
  66.  
  67. A note on string variables:
  68.     All string variables use null terminated strings. They are pointers to
  69.     arrays of characters.
  70.  
  71. A note on coordinate variables:
  72.     All coordinate variable are virtual coordinates (0-10000 by 0-10000)
  73.     unless otherwise noted.
  74.  
  75. A note on fillstyle variables:
  76.     All fillstyle variables ues the same values as the standard BGI.
  77.  
  78. A note on 256 color palettes:
  79.     All 256 color palettes are stored in an array[256] of palrec.
  80.  
  81. A note on areas:
  82.     All areas for fills, getting bitmaps, etc. are defined by the coordinates
  83.     of the upper left (x1,y1) and lower right (x2,y2) corners.
  84.  
  85. A note on text variables:
  86.     All of the following text variable types use the standard values of the
  87.     BGI: font, textsize, orientation, horizontal and vertical justifications,
  88.     and scaling factors.
  89.  
  90. ==============================================================================
  91.  
  92. Edit.c:
  93.     This library provides a basic ascii text editor that runs in graphics
  94.     mode. It contains one routine:
  95.  
  96.     --------------------------------------------------------------------------
  97.  
  98.     void editfile(char *s,int fore,int fore2,int bak);
  99.  
  100.     S is the name of the ascii file to edit. Fore is text color. Fore2 is 
  101.     text shadow color. Bak is background color. This routine draws a large 
  102.     panel on the screen and shows the text on the panel. Editing keys work 
  103.     in the usual manner. Pressing Esc exits with an option to save. Example:
  104.  
  105.     #include <graphics.h>
  106.     #include <edit.h>
  107.     #include <graf.h>
  108.     #include <mouse.h>
  109.     void main()
  110.     {
  111.     vidmode=0;
  112.     grafon();
  113.     resetmouse();
  114.           /* edit autoexec.bat using white text
  115.              with black shadow on blue background. */
  116.     editfile("c:\\autoexec.bat",15,0,1);
  117.     closegraph();
  118.     }
  119.  
  120. ==============================================================================
  121.  
  122. Fileio.c:
  123.     This library provides easy to use routines for both text and binary file
  124.     input and output. Use these routines instead of fopen, fread, etc. The
  125.     routines in this library call fopen, fread, etc. for you with the proper
  126.     parameters. This library's .h file includes stdio.h. This means you
  127.     don't have to include stdio.h in files that include fileio.h. The
  128.     routines in fileio.c are as follows:
  129.  
  130.     --------------------------------------------------------------------------
  131.  
  132.     int filefound(char *s);
  133.  
  134.     Searches for a file. S is the name of the file to search for. Returns a 1
  135.     if the file is found, else returns a 0. Example:
  136.  
  137.     #include <fileio.h>
  138.     void main()
  139.     {
  140.     if (filefound("c:\\autoexec.bat")) printf("autoexec found\n");
  141.     else printf("autoexec not found\n");
  142.     }
  143.  
  144.     --------------------------------------------------------------------------
  145.  
  146.     int readfile(FILE *f,char *s);
  147.  
  148.     Reads a string from an ascii text file. F is the file to read from.
  149.     S is the string to read into. returns 1 on success, else returns 0.
  150.     Example:
  151.  
  152.     #include <fileio.h>
  153.     char s[100];
  154.     FILE *f;
  155.     void main()
  156.     {
  157.     f=infile("c:\\autoexec.bat");
  158.     while (readfile(f,s)) printf("%s",s);
  159.     fclose(f);
  160.     }
  161.  
  162.     --------------------------------------------------------------------------
  163.  
  164.     int writefile(FILE *f,char *s);
  165.  
  166.     Writes a string to an ascii text file with a cr/lf. F is the file to
  167.     write to. S is the string to write. Returns 1 on success, else returns 0.
  168.     Example:
  169.  
  170.     #include <fileio.h>
  171.     FILE *f;
  172.     void main()
  173.     {
  174.     f=outfile("test.doc");
  175.     writefile(f,"this is a test.");
  176.     fclose(f);
  177.     }
  178.  
  179.     --------------------------------------------------------------------------
  180.  
  181.     int writefile2(FILE *f,char *s);
  182.  
  183.     Writes a string to an ascii text file without a cr/lf. F is the file to
  184.     write to. S is the string to write. Returns 1 on success, else returns 0.
  185.     Example:
  186.  
  187.     #include <fileio.h>
  188.     FILE *f;
  189.     void main()
  190.     {
  191.     f=outfile("test.doc");
  192.     writefile2(f,"this is");
  193.     writefile(f," a test.");    /* writes: this is a test. */
  194.     fclose(f);
  195.     }
  196.  
  197.     --------------------------------------------------------------------------
  198.  
  199.     FILE *infile(char *s);
  200.  
  201.     Opens an ascii text file for input. S is the name of the file to open.
  202.     Returns a file pointer for the opened file. Example:
  203.  
  204.     #include <fileio.h>
  205.     char s[100];
  206.     FILE *f;
  207.     void main()
  208.     {
  209.     f=infile("c:\\autoexec.bat");
  210.     while (readfile(f,s)) printf("%s\n",s);
  211.     fclose(f);
  212.     }
  213.  
  214.     --------------------------------------------------------------------------
  215.  
  216.     FILE *outfile(char *s);
  217.  
  218.     Opens an ascii text file for output. S is the name of the file to open.
  219.     Returns a file pointer for the newly opened file. Example:
  220.  
  221.     #include <fileio.h>
  222.     FILE *f;
  223.     void main()
  224.     {
  225.     f=outfile("test.doc");
  226.     writefile(f,"this is a test.");
  227.     fclose(f);
  228.     }
  229.  
  230.     --------------------------------------------------------------------------
  231.  
  232.     FILE *appendfile(char *s);
  233.  
  234.     Opens an ascii file for appending output to the end of the file. S is the
  235.     name of the file to open. Returns a file pointer to the newly opened
  236.     file. Example:
  237.  
  238.     #include <fileio.h>
  239.     FILE *f;
  240.     void main()
  241.     {
  242.     f=appendfile("c:\\autoexec.bat");
  243.     writefile(f,"echo Hello World!");
  244.     fclose(f);
  245.     }
  246.  
  247.     --------------------------------------------------------------------------
  248.  
  249.     FILE *appendfilebin(char *s);
  250.  
  251.     Opens a binary file for appending output to the end of the file. S is the
  252.     name of the file to open. Returns a file pointer to the newly opened
  253.     file. Example:
  254.  
  255.     #include <string.h>
  256.     #include <fileio.h>
  257.     struct addressrec
  258.        {
  259.        char name[20],address[50],phone[20];
  260.        };
  261.     struct addressrec r;
  262.     FILE *f;
  263.     void main()
  264.     {
  265.     strcpy(r.name,"Joe Blow");
  266.     strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
  267.     strcpy(r.phone,"703-555-1212");
  268.     f=appendfilebin("address.dat");
  269.     writefilebin(f,&r,sizeof(r));
  270.     fclose(f);
  271.     }
  272.  
  273.     --------------------------------------------------------------------------
  274.  
  275.     FILE *infilebin(char *s);
  276.  
  277.     Opens a binary file for input. S is the name of the file to open. Returns
  278.     a file pointer to the newly opened file. Example:
  279.  
  280.     #include <fileio.h>
  281.     struct addressrec
  282.        {
  283.        char name[20],address[50],phone[20];
  284.        };
  285.     struct addressrec r;
  286.     FILE *f;
  287.     void main()
  288.     {
  289.     f=infilebin("address.dat");
  290.     readfilebin(f,&r,sizeof(r));
  291.     fclose(f);
  292.     printf("%s\n",r.name);
  293.     printf("%s\n",r.address);
  294.     printf("%s\n",r.phone);
  295.     }
  296.  
  297.     --------------------------------------------------------------------------
  298.  
  299.     FILE *outfilebin(char *s);
  300.  
  301.     Opens a binary file for output. S is the name of the file to open.
  302.     Returns a file pointer to the newly opened file. Example:
  303.  
  304.     #include <fileio.h>
  305.     struct addressrec
  306.        {
  307.        char name[20],address[50],phone[20];
  308.        };
  309.     struct addressrec r;
  310.     FILE *f;
  311.     void main()
  312.     {
  313.     strcpy(r.name,"Joe Blow");
  314.     strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
  315.     strcpy(r.phone,"703-555-1212");
  316.     f=outfilebin("address.dat");
  317.     writefilebin(f,&r,sizeof(r));
  318.     fclose(f);
  319.     }
  320.  
  321.     --------------------------------------------------------------------------
  322.  
  323.     int readfilebin(FILE *f,void *rec,int recsize);
  324.  
  325.     Reads a record from a binary file. F is the file pointer of the file to
  326.     read from. Rec points to the record to read into. Recsize is the size (in
  327.     bytes) of the record to be read. Example:
  328.  
  329.     #include <fileio.h>
  330.     struct addressrec
  331.        {
  332.        char name[20],address[50],phone[20];
  333.        };
  334.     struct addressrec r;
  335.     FILE *f;
  336.     void main()
  337.     {
  338.     f=infilebin("address.dat");
  339.     readfilebin(f,&r,sizeof(r));
  340.     fclose(f);
  341.     printf("%s\n",r.name);
  342.     printf("%s\n",r.address);
  343.     printf("%s\n",r.phone);
  344.     }
  345.  
  346.     --------------------------------------------------------------------------
  347.  
  348.     int writefilebin(FILE *f,void *rec,int recsize);
  349.  
  350.     Writes a record to a binary file. F is the file pointer of the file to
  351.     write to. Rec points to the record to write. Recsize is the size (in
  352.     bytes) of the record to be written. Example:
  353.  
  354.     #include <fileio.h>
  355.     struct addressrec
  356.        {
  357.        char name[20],address[50],phone[20];
  358.        };
  359.     struct addressrec r;
  360.     FILE *f;
  361.     void main()
  362.     {
  363.     strcpy(r.name,"Joe Blow");
  364.     strcpy(r.address,"123 anystreet, Fairfax VA, 22033");
  365.     strcpy(r.phone,"703-555-1212");
  366.     f=outfilebin("address.dat");
  367.     writefilebin(f,&r,sizeof(r));
  368.     fclose(f);
  369.     }
  370.  
  371. ==============================================================================
  372.  
  373. Generic2.c:
  374.  
  375.     This library provides miscellaneous routines. It includes sound, keyboard,
  376.     string, and dos routines. Routines are as follows:
  377.  
  378.     --------------------------------------------------------------------------
  379.  
  380.     void beep(int f, int d);
  381.  
  382.     Produces a beep on the PC's speaker. F is the frequency (in Hertz) of the
  383.     beep. D is the duration of the beep in milliseconds. Example:
  384.  
  385.     #include <generic2.h>
  386.     void main()
  387.     {
  388.      /* produces a beep similar to character 7, the bell character */
  389.     beep(1000,100);
  390.     }
  391.  
  392.     --------------------------------------------------------------------------
  393.  
  394.     void nokey();
  395.  
  396.     Waits until no keyboard keys are being pressed. Example:
  397.  
  398.     #include <stdio.h>
  399.     #include <conio.h>
  400.     #include <generic2.h>
  401.     void main()
  402.     {
  403.     printf("Press a key to continue...\n");
  404.     nokey();
  405.     /* waits for no keystrokes, emptying keyboard buffer, then continues */
  406.     getch();   /* gets a keystroke */
  407.     }
  408.  
  409.     --------------------------------------------------------------------------
  410.  
  411.     int inserton();
  412.  
  413.     Returns 1 if insert is on, else returns 0. Example:
  414.  
  415.     #include <stdio.h>
  416.     #include <generic2.h>
  417.     void main()
  418.     {
  419.     if (inserton()) printf("insert is on\n");
  420.     else printf("insert is off\n");
  421.     }
  422.  
  423.     --------------------------------------------------------------------------
  424.  
  425.     void delchar(char *s,int first,int num);
  426.  
  427.     Deletes characters from a string. S is the (null terminated) string to
  428.     delete characters from. First is the 1st character to delete (zero based,
  429.     just like character arrays). Num is the number of characters to delete.
  430.     Example:
  431.  
  432.     #include <stdio.h>
  433.     #include <string.h>
  434.     #include <generic2.h>
  435.     void main()
  436.     {
  437.     strcpy(s,"joe blow");
  438.       /* delete 5 characters from S, starting with character 3. */
  439.     delchar(s,3,5);
  440.     printf("%s\n",s);      /* prints out "joe" */
  441.     }
  442.  
  443.     --------------------------------------------------------------------------
  444.  
  445.     void copyfile(char *s,char *s2);
  446.  
  447.     Copies a file. S is the source filename. S2 is the destination filename.
  448.     Example:
  449.  
  450.     #include <generic2.h>
  451.     void main()
  452.     {
  453.     copyfile("c:\\autoexec.bat","c:\\autoexec.bak"); /* backup the autoexec */
  454.     }
  455.  
  456.     --------------------------------------------------------------------------
  457.  
  458.     void chdrv(int i);
  459.  
  460.     Changes the current drive. I is the drive to change to (0=A:, 1=B:, 2=C:,
  461.     etc.). Example:
  462.  
  463.     #include <generic2.h>
  464.     void main()
  465.     {
  466.     chdrv(2);     /*     change to C:    */
  467.     }
  468.  
  469.     --------------------------------------------------------------------------
  470.  
  471.     int deviceready(char *s);
  472.  
  473.     Returns 1 if device s is ready. Otherwise returns 0. S can be: "prn",
  474.     "lpt1", "lpt2", "lpt3", "com1", "com2", "com3", or "com4". Example:
  475.  
  476.     #include <generic2.h>
  477.     #include <stdio.h>
  478.     void main()
  479.     {
  480.     if (deviceready("prn")) printf("Printer is ready...\n");
  481.     else printf("Error: printer not ready.\n");
  482.     }
  483.  
  484.     --------------------------------------------------------------------------
  485.  
  486.     void stringcopy(char *fromstr,char *tostr,int startchar,int numchars);
  487.  
  488.     Copies part of a string to another string. Fromstr is the string to copy
  489.     from. Tostr is the string to copy to. Startchar is the first character to
  490.     copy (zero based). Numchars is the number of characters to copy. Example:
  491.  
  492.     #include <generic2.h>
  493.     #include <stdio.h>
  494.     #include <string.h>
  495.     void main()
  496.     {
  497.     strcpy(s,"This is a test");
  498.     stringcopy(s,s2,5,4);
  499.     printf("%s\n",s2);          /* prints "is a".   */
  500.     }
  501.  
  502.     --------------------------------------------------------------------------
  503.  
  504.     void doscommand(char *s);
  505.  
  506.     Executes a dos command. S is the command as you would enter it at the dos
  507.     prompt. Example:
  508.  
  509.     #include <generic2.h>
  510.     #include <stdio.h>
  511.     #include <conio.h>
  512.     void main()
  513.     {
  514.     char s[100],s2[100];
  515.     printf("Enter search spec...\n");
  516.     scanf("%s",s);
  517.     strcpy(s2,"dir ");
  518.     strcat(s2,s);
  519.     doscommand(s2);
  520.     printf("Press a key...\n");
  521.     getch();
  522.     }
  523.  
  524.     --------------------------------------------------------------------------
  525.  
  526.     void slash(char *s);
  527.  
  528.     Adds a backslash to the end of string s if the last character is not a
  529.     backslash. Use this to add a backslash (if needed) to a directory name
  530.     before adding a filename to the end of the dirctory name. Example:
  531.  
  532.     #include <generic2.h>
  533.     #include <string.h>
  534.     void main()
  535.     {
  536.     char s[100];
  537.     strcpy(s,"c:\\");          /*    s = "c:\"               */
  538.     slash(s);                  /*    s = "c:\"               */
  539.     strcat(s,"command.com");   /*    s = "c:\command.com"    */
  540.     strcpy(s,"c:\\dos");       /*    s = "c:\dos"            */
  541.     slash(s);                  /*    s = "c:\dos\"           */
  542.     strcat(s,"edit.exe");      /*    s = "c:\dos\edit.exe"   */
  543.     }
  544.  
  545.     --------------------------------------------------------------------------
  546.  
  547.     void filenameonly(char *fullname,char *filename);
  548.  
  549.     Returns the filename and extension of a full filename. Fullname is the
  550.     complete filename (drive, directory, filename, and extension). The
  551.     filename with extension is returned in the string <filename>. Example:
  552.  
  553.     #include <generic2.h>
  554.     #include <string.h>
  555.     void main()
  556.     {
  557.     char s[100],s2[100];
  558.     strcpy(s,"c:\\command.com");
  559.     filenameonly(s,s2);            /* returns "command.com" in s2 */
  560.     }
  561.  
  562.     --------------------------------------------------------------------------
  563.  
  564.     long diskfree(int i);
  565.  
  566.     Returns the number of bytes free on a disk. I is the disk (0=current
  567.     drive, 1=A:, 2=B:, 3=C:, etc). Returns -1 if i is not a valid drive.
  568.  
  569. ==============================================================================
  570.  
  571. Graf.c:
  572.     This library provides device independant graphics. It works on a virtual
  573.     coordinate system 0 to 10000 by 0 to 10000 which is then automatically
  574.     mapped to the resolution of the video mode being run (ie 640x480,
  575.     1024x768, etc.). It contains a wide range of routines for graphics.
  576.     It also declares some data structures for use in graphics programming.
  577.     Data structures are as follows:
  578.  
  579.     --------------------------------------------------------------------------
  580.  
  581.     struct palrec
  582.        {
  583.        unsigned char redval,greenval,blueval;
  584.        };
  585.  
  586.     This record type holds the information for one palette entry of a 256
  587.     color palette. It is usually used as the element of an array[256] which
  588.     is a 256 color palette (ie: struct palrec mypal[256]; ). Example:
  589.  
  590.     #include <graphics.h>
  591.     #include <graf.h>
  592.      /* note that PAL, a 256 color palette, is declared as an array[256]
  593.     (ie 0 to 255) of palrec!   */
  594.     struct palrec pal[256];
  595.     void main()
  596.     {
  597.     grafmode=1;
  598.     grafon();
  599.     getallrgbpalette(pal);   /* copy current palette into PAL */
  600.     savepal("default.pal",pal);       /* save PAL to disk */
  601.     closegraph();
  602.     }
  603.  
  604.     --------------------------------------------------------------------------
  605.  
  606.     extern int graffontsize;
  607.  
  608.     This variable is set automatically by the grafon() routine. It is the
  609.     text size used by the menus, dialog boxes, etc in the BC 40 Lib library.
  610.     It is set so that text will be approximately the same size reguardless of
  611.     what video mode you are running. Use it in your saygraf, saygraf3d, and
  612.     settextstyle calls to keep text device independant. It is designed to
  613.     yield approximately 3/8 inch tall characters when font #2 (litt.chr) is
  614.     used. Example:
  615.  
  616.     #include <conio.h>
  617.     #include <graphics.h>
  618.     #include <graf.h>
  619.     void main()
  620.     {
  621.     vidmode=0;
  622.     grafon();
  623.     saygraf3d(5000,5000,15,7,2,graffontsize,0,1,1,1,1,1,1,"Hello world!");
  624.     getch();
  625.     closegraph();
  626.     }
  627.  
  628.     --------------------------------------------------------------------------
  629.  
  630.     extern int vidmode;
  631.  
  632.     This variable is set by you before you call grafon(). It tells grafon()
  633.     what graphics mode to go into. It also can be used to determine what
  634.     graphics mode you're in once you call grafon(). Allowable values are:
  635.     0 - vga 640x350x16 2 vid pages
  636.     1 - vga 648x480x16
  637.     2 - vga 320x200x256*
  638.     3 - vesa svga 640x400x256*
  639.     4 - vesa svga 640x480x256*
  640.     5 - vesa svga 800x600x256*
  641.     6 - vesa svga 1024x768x256*
  642.     * requires bgi256v2.bgi, a popular sharware VESA SVGA bgi driver
  643.       (not included).
  644.     Example:
  645.  
  646.     #include <graphics.h>
  647.     #include <conio.h>
  648.     #include <graf.h>
  649.     void main()
  650.     {
  651.     vidmode=1;   /* set graphics to start in 640x480x16 VGA. */
  652.     grafon();    /* go to graphics mode */
  653.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Hello world!");
  654.     getch();
  655.     closegraph();   /* end graphics mode, return to text mode */
  656.     }
  657.  
  658.     --------------------------------------------------------------------------
  659.  
  660.     extern char m[25][100];
  661.  
  662.     This array of strings is used by the menus and dialog boxes in the Graf
  663.     library. It is used to hold menu options, or dialog box text. When
  664.     you aren't calling routines that use the array, you may use it for your
  665.     own purposes. To use it with a routine such as a menu, you first copy
  666.     the desired strings into the array, and then call the menu routine. The
  667.     menu routine will use the text in the array for the menu. Example:
  668.  
  669.     #include <graf.h>
  670.     #include <graphics.h>
  671.     #include <mouse.h>
  672.     #include <string.h>
  673.     int i;
  674.     void main()
  675.     {
  676.     vidmode=1;
  677.     grafon();
  678.     resetmouse();
  679.     /* load menu options into array */
  680.     strcpy(m[0],"Please select...");
  681.     strcpy(m[1],"Yes");
  682.     strcpy(m[2],"No");
  683.     /* call menu routine */
  684.     i=popupmenu(-1,-1,2,15,0,1,1);
  685.     if (i==1)
  686.        saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Yes selected");
  687.     else saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"No selected");
  688.     nobutton();
  689.     do
  690.       {
  691.       }
  692.       while (mousebutton()==0);
  693.     closegraph();
  694.     }
  695.  
  696.     --------------------------------------------------------------------------
  697.  
  698.     void loadpal(char *s, struct palrec *pal);
  699.  
  700.     This routine loads a 256 color palette from disk into an array[256] of
  701.     palrec. S is the filename of the palette data file to load. Pal is a
  702.     pointer to an array[256] of palrec that the palette will be read into.
  703.     Example:
  704.  
  705.     #include <conio.h>
  706.     #include <graphics.h>
  707.     #include <graf.h>
  708.     struct palrec pal[256];
  709.     void main()
  710.     {
  711.     grafmode=2;
  712.     grafon();
  713.     loadpal("test.pal",pal);   /* load test.pal from disk into PAL*/
  714.     setallrgbpalette(pal);     /* set palette to PAL */
  715.     getch();
  716.     closegraph();
  717.     }
  718.  
  719.     --------------------------------------------------------------------------
  720.  
  721.     void savepal(char *s, struct palrec *pal);
  722.  
  723.     Saves a 256 color palette to disk. S is the name of the palette data file
  724.     to create. Pal is a pointer to an array[256] of palrec, which is the
  725.     palette to be saved. Example:
  726.  
  727.     #include <graphics.h>
  728.     #include <graf.h>
  729.     struct palrec pal[256];
  730.     void main()
  731.     {
  732.     grafmode=1;
  733.     grafon();
  734.     getallrgbpalette(pal);   /* copy current palette into PAL */
  735.     savepal("default.pal",pal);       /* save PAL to disk */
  736.     closegraph();
  737.     }
  738.  
  739.     --------------------------------------------------------------------------
  740.  
  741.     void setallrgbpalette(struct palrec *pal);
  742.  
  743.     Sets the computer's 256 color palette. Pal points to an array[256] of
  744.     palrec that contains the new values for the computer's palette. Uses
  745.     a rom bios interrupt call to set the palette. Example:
  746.  
  747.     #include <conio.h>
  748.     #include <graphics.h>
  749.     #include <graf.h>
  750.     struct palrec pal[256];
  751.     void main()
  752.     {
  753.     grafmode=2;
  754.     grafon();
  755.     loadpal("test.pal",pal);   /* load test.pal from disk into PAL*/
  756.     setallrgbpalette(pal);     /* set palette to PAL */
  757.     getch();
  758.     closegraph();
  759.     }
  760.  
  761.     --------------------------------------------------------------------------
  762.  
  763.     int x2vidx(int x);
  764.  
  765.     Converts a virtual x coordinate to a hardware x coordinate. X is the
  766.     virtual x coordinate to convert. Returns the hardware x coordinate.
  767.     Example:
  768.  
  769.     #include <graf.h>
  770.     #include <graphics.h>
  771.     #include <stdio.h>
  772.     int i;
  773.     void main()
  774.     {
  775.     vidmode=2;   /* 640x480x16 */
  776.     grafon();
  777.     i=x2vidx(10000);
  778.     closegraph();
  779.     printf("%d\n",i);   /* prints 639 */
  780.     }
  781.  
  782.     --------------------------------------------------------------------------
  783.  
  784.     int y2vidy(int y);
  785.  
  786.     Converts a virtual y coordinate to a hardware y coordinate. Y is the
  787.     virtual y coordinate to convert. Returns the hardware y coordinate.
  788.     Example:
  789.  
  790.     #include <graf.h>
  791.     #include <graphics.h>
  792.     #include <stdio.h>
  793.     int i;
  794.     void main()
  795.     {
  796.     vidmode=2;   /* 640x480x16 */
  797.     grafon();
  798.     i=y2vidy(10000);
  799.     closegraph();
  800.     printf("%d\n",i);   /* prints 479 */
  801.     }
  802.  
  803.     --------------------------------------------------------------------------
  804.  
  805.     int mousex2x(int x);
  806.  
  807.     Converts a harware or mouse x coordinate to a virtual x coordinate. X is
  808.     the hardware or mouse x coordinate to convert. Returns the virtual x
  809.     coordinate. Example:
  810.  
  811.     #include <graf.h>
  812.     #include <graphics.h>
  813.     #include <stdio.h>
  814.     int i;
  815.     void main()
  816.     {
  817.     vidmode=2;   /* 640x480x16 */
  818.     grafon();
  819.     i=mousex2x(639);
  820.     closegraph();
  821.     printf("%d\n",i);   /* prints 10000 */
  822.     }
  823.  
  824.     --------------------------------------------------------------------------
  825.  
  826.     int mousey2y(int y);
  827.  
  828.     Converts a harware or mouse y coordinate to a virtual y coordinate. Y is
  829.     the hardware or mouse y coordinate to convert. Returns the virtual y
  830.     coordinate. Example:
  831.  
  832.     #include <graf.h>
  833.     #include <graphics.h>
  834.     #include <stdio.h>
  835.     int i;
  836.     void main()
  837.     {
  838.     vidmode=2;   /* 640x480x16 */
  839.     grafon();
  840.     i=mousey2y(479);
  841.     closegraph();
  842.     printf("%d\n",i);   /* prints 10000 */
  843.     }
  844.  
  845.     --------------------------------------------------------------------------
  846.  
  847.     void grafpie(int x, int y, int startangle, int endangle, int radius,
  848.          int color, int fillstyle);
  849.  
  850.     Draws a filled pieslice. x,y are the point of the pieslice. Startangle is
  851.     the angle (in degrees) of the beginning edge of the pieslice. Endangle
  852.     is the angle (in degrees) of the ending edge of the pieslice. Radius is
  853.     the radius of the pieslice in virual coordinates. Color is the color of
  854.     the pieslice, and Fillstyle is the fill pattern used to fill the pieslice.
  855.     Example:
  856.  
  857.     #include <graf.h>
  858.     #include <graphics.h>
  859.     #include <conio.h>
  860.     void main()
  861.     {
  862.     vidmode=1;
  863.     grafon();
  864.     pieslice(5000,5000,0,45,4000,14,9);
  865.     getch();
  866.     closegraph();
  867.     }
  868.  
  869.     --------------------------------------------------------------------------
  870.  
  871.     void *grafload(char *s);
  872.  
  873.     Loads a bitmap from disk. S is the filename of the bitmap to load from
  874.     disk. Returns a pointer to the bitmap. Once you're done with the bitmap,
  875.     don't forget to dispose of it by calling free(). Example:
  876.  
  877.     #include <conio.h>
  878.     #include <graf.h>
  879.     #include <graphics.h>
  880.     void *p;
  881.     void main()
  882.     {
  883.     vidmode=1;
  884.     grafon();
  885.     p=grafload("bitmap1.grf");
  886.     grafput(0,0,0,p);
  887.     free(p);
  888.     getch();
  889.     closegraph();
  890.     }
  891.  
  892.     --------------------------------------------------------------------------
  893.  
  894.     void grafsave(char *s,void *p);
  895.  
  896.     Saves a bitmap to disk. S is the filename to save as. P points to the
  897.     bitmap to save. Once you're done with a bitmap, don't forget to dispose
  898.     of it by calling free(). Example:
  899.  
  900.     #include <graf.h>
  901.     #include <graphics.h>
  902.     void *p;
  903.     void main()
  904.     {
  905.     vidmode=1;
  906.     grafon();
  907.     fillgraf(2000,2000,3000,3000,14,9);
  908.     p=grafget(1000,1000,4000,4000);
  909.     grafsave("test.grf",p);
  910.     free(p);
  911.     closegraph();
  912.     }
  913.  
  914.     --------------------------------------------------------------------------
  915.  
  916.     void getallrgbpalette(struct palrec *pal);
  917.  
  918.     Gets the current 256 color palette. Puts the current palette values into
  919.     Pal. Example:
  920.  
  921.     #include <graphics.h>
  922.     #include <graf.h>
  923.     struct palrec pal[256];
  924.     void main()
  925.     {
  926.     grafmode=1;
  927.     grafon();
  928.     getallrgbpalette(pal);   /* copy current palette into PAL */
  929.     savepal("default.pal",pal);       /* save PAL to disk */
  930.     closegraph();
  931.     }
  932.  
  933.     --------------------------------------------------------------------------
  934.  
  935.     void fillgraf(int x1,int y1,int x2,int y2,int color,int fill);
  936.  
  937.     Fills a rectangular area with a color and fillstyle. x1,y1,x2,y2 are
  938.     the coordinates of the area to fill. Color is the color to fill the area
  939.     with. Fill is the fillstyle to use when filling the area. Example:
  940.  
  941.     #include <conio.h>
  942.     #include <graf.h>
  943.     #include <graphics.h>
  944.     void main()
  945.     {
  946.     grafmode=1;
  947.     grafon();
  948.     fillgraf(1000,1000,2000,2000,14,9);
  949.     getch();
  950.     closegraph();
  951.     }
  952.  
  953.     --------------------------------------------------------------------------
  954.  
  955.     void clsgraf(int color,int fill);
  956.  
  957.     Clears the screen. Color is the color to be used. Fill is the fillstyle
  958.     to be used. Example:
  959.  
  960.     #include <conio.h>
  961.     #include <graf.h>
  962.     #include <graphics.h>
  963.     void main()
  964.     {
  965.     vidmode=1;
  966.     grafon();
  967.     clsgraf(14,9);
  968.     getch();
  969.     closegraph();
  970.     }
  971.  
  972.     --------------------------------------------------------------------------
  973.  
  974.     void grafon();
  975.  
  976.     Turns on graphics. Use instead of initgraph(). Set vidmode to the
  977.     desired video mode before calling grafon(). This routine sets
  978.     graffontsize according to the vidmode selected. Don't forget to
  979.     use closegraph() to turn off graphics mode when you're done with
  980.     graphics mode. Example:
  981.  
  982.     #include <conio.h>
  983.     #include <graf.h>
  984.     #include <graphics.h>
  985.     void main()
  986.     {
  987.     vidmode=1;
  988.     grafon();
  989.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"640x480x16");
  990.     getch();
  991.     closegraph();
  992.     }
  993.  
  994.     --------------------------------------------------------------------------
  995.  
  996.     void saygraf3d(int x, int y, int fore, int bak, int font, int size,
  997.            int orientation, int hjust, int vjust, int xmul, int xdiv,
  998.            int ymul, int ydiv,const char *s);
  999.  
  1000.     Writes 3D text on the screen. Writes text at position x,y. Fore and
  1001.     Bak are the text and text shadow colors. Font is the font to use.
  1002.     Size is the size of the text. Orientation is 0 for horizontal, or
  1003.     1 for vertical. Hjust and Vjust are the horizontal and vertical
  1004.     justification to use. They work the same as in the BGI routine
  1005.     settextjustify(). Xmul, Xdiv, Ymul, and Ydiv are scaleing factors. They
  1006.     work the same as in the BGI routine setusercharsize(). S is the string of
  1007.     text to write to the screen. Example:
  1008.  
  1009.     #include <conio.h>
  1010.     #include <graf.h>
  1011.     #include <graphics.h>
  1012.     void main()
  1013.     {
  1014.     vidmode=1;
  1015.     grafon();
  1016.     saygraf3d(5000,5000,15,7,2,graffontsize,0,1,1,1,1,1,1,"3D Text");
  1017.     getch();
  1018.     closegraph();
  1019.     }
  1020.  
  1021.     --------------------------------------------------------------------------
  1022.  
  1023.     void saygraf(int x, int y, int fore, int font, int size, int orientation,
  1024.          int hjust, int vjust, int xmul, int xdiv, int ymul, int ydiv,
  1025.          char *s);
  1026.  
  1027.     Writes text on the screen. Writes text at position x,y. Fore is the text
  1028.     color. Font is the font to use. Size is the size of the text. Orientation
  1029.     is 0 for horizontal, or 1 for vertical. Hjust and Vjust are the
  1030.     horizontal and vertical justification to use. They work the same as in
  1031.     the BGI routine settextjustify(). Xmul, Xdiv, Ymul, and Ydiv are
  1032.     scaleing factors. They work the same as in the BGI routine
  1033.     setusercharsize(). S is the string of text to write to the screen.
  1034.     Example:
  1035.  
  1036.     #include <conio.h>
  1037.     #include <graf.h>
  1038.     #include <graphics.h>
  1039.     void main()
  1040.     {
  1041.     vidmode=1;
  1042.     grafon();
  1043.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"This is some text");
  1044.     getch();
  1045.     closegraph();
  1046.     }
  1047.  
  1048.     --------------------------------------------------------------------------
  1049.  
  1050.     void *grafget(int x1,int y1,int x2,int y2);
  1051.  
  1052.     Gets an area from the screen and stores it in a bitmap. x1,y1,x2,y2 are
  1053.     the coordinates of the area to get. Returns a pointer to the bitmap.
  1054.     Don't forget to dispose of the bitmap when you're done with it by calling
  1055.     free(). Example:
  1056.  
  1057.     #include <graf.h>
  1058.     #include <graphics.h>
  1059.     void *p;
  1060.     void main()
  1061.     {
  1062.     vidmode=1;
  1063.     grafon();
  1064.     fillgraf(2000,2000,3000,3000,14,9);
  1065.     p=grafget(1000,1000,4000,4000);
  1066.     grafsave("test.grf",p);
  1067.     free(p);
  1068.     closegraph();
  1069.     }
  1070.  
  1071.     --------------------------------------------------------------------------
  1072.  
  1073.     void grafline(int x1,int y1,int x2,int y2,int color,int style,
  1074.           int thickness);
  1075.  
  1076.     Draws a line. x1,y1 and x2,y2 are the endpoints of the line. Color is
  1077.     the color to use. Style is the line style. It uses standard BGI line
  1078.     style constants just like the standard BGI routine setlinestyle() does.
  1079.     Thickness is the line thickness. It uses standard BGI line thickness
  1080.     constants just like the standard BGI routine setlinestyle(). Example:
  1081.  
  1082.     #include <conio.h>
  1083.     #include <graf.h>
  1084.     #include <graphics.h>
  1085.     void main()
  1086.     {
  1087.     vidmode=1;
  1088.     grafon();
  1089.     grafline(1000,1000,9000,9000,15,0,1);
  1090.     getch();
  1091.     closegraph();
  1092.     }
  1093.  
  1094.     --------------------------------------------------------------------------
  1095.  
  1096.     void grafpix(int x, int y, int color);
  1097.  
  1098.     Draws a pixel on the screen. X,Y are the pixel coordinates. Color is the
  1099.     color to draw the pixel. Example:
  1100.  
  1101.     #include <conio.h>
  1102.     #include <graf.h>
  1103.     #include <graphics.h>
  1104.     int i;
  1105.     void main()
  1106.     {
  1107.     vidmode=1;
  1108.     grafon();
  1109.     for (i=0; i<=10000; i+=100) grafpix(i,i,15);
  1110.     getch();
  1111.     closegraph();
  1112.     }
  1113.  
  1114.     --------------------------------------------------------------------------
  1115.  
  1116.     void panel(int x1, int y1, int x2, int y2, int color, int pressed);
  1117.  
  1118.     Draws a beveled panel. x1,y1,x2,y2 is the area the panel covers. Color
  1119.     is the panel color. Pressed is a boolean. Set Pressed = 1 for pressed
  1120.     in look. Set Pressed = 0 for popped out look. Example:
  1121.  
  1122.     #include <conio.h>
  1123.     #include <graf.h>
  1124.     #include <graphics.h>
  1125.     int i;
  1126.     void main()
  1127.     {
  1128.     vidmode=1;
  1129.     grafon();
  1130.     panel(3000,3000,7000,7000,7,0);
  1131.     panel(4000,4000,5000,4500,9,0);
  1132.     panel(4000,5000,5000,5500,7,1);
  1133.     getch();
  1134.     closegraph();
  1135.     }
  1136.  
  1137.     --------------------------------------------------------------------------
  1138.  
  1139.     void graftri(int x1,int y1,int x2,int y2,int x3,int y3,int color,
  1140.          int fill);
  1141.  
  1142.     Draws a triangle. x1,y1,xc2,y2,x3,y3 are the corners of the triangle.
  1143.     Color and Fill are the color and fillstyle for the triangle. Example:
  1144.  
  1145.     #include <conio.h>
  1146.     #include <graf.h>
  1147.     #include <graphics.h>
  1148.     int i;
  1149.     void main()
  1150.     {
  1151.     vidmode=1;
  1152.     grafon();
  1153.     graftri(1000,9000,5000,1000,9000,9000,13,10);
  1154.     getch();
  1155.     closegraph();
  1156.     }
  1157.  
  1158.     --------------------------------------------------------------------------
  1159.  
  1160.     void grafput(int x, int y, int put, void *p);
  1161.  
  1162.     Puts a bitmap to the screen. x,y is the upper left corner for the bitmap.
  1163.     Put is a standard BGI put type constant just like in the standard BGI
  1164.     routine putimage(). Note that you may also use the extended put types
  1165.     available with BGI256V2.BGI, a popular shareware VESA SVGA BGI driver.
  1166.     Example:
  1167.  
  1168.     #include <conio.h>
  1169.     #include <graf.h>
  1170.     #include <graphics.h>
  1171.     void *p;
  1172.     void main()
  1173.     {
  1174.     vidmode=1;
  1175.     grafon();
  1176.     p=grafload("bitmap1.grf");
  1177.     grafput(0,0,0,p);
  1178.     free(p);
  1179.     getch();
  1180.     closegraph();
  1181.     }
  1182.  
  1183.     --------------------------------------------------------------------------
  1184.  
  1185.     void grafmsg(int x, int y, int i, int fore,int fore2, int bak,
  1186.          int doclick,int dopause, int doprint);
  1187.  
  1188.     Displays a message box. x,y are the upper left corner of the box. If
  1189.     x=-1, box will be centered left to right. If y=-1, box will be centered
  1190.     top to bottom. I is the index of the last string in the message (ie. for
  1191.     a message that uses m[0] thru m[7], i=7). Fore and Fore2 are the text and
  1192.     text shadow colors. Bak is the box color. Uses the global array of
  1193.     strings m[] to hold the text.
  1194.     If doprint=1: the box won't be drawn at all, and the contents will be
  1195.           printed to PRN. Dopause and Doclick are ignored.
  1196.     If doprint=0: If dopause=1: the screen behind the box will be saved, and
  1197.                 the last line of the message box will read
  1198.                 "Press P to print or a mouse button to
  1199.                 continue...". When a mouse button is pressed,
  1200.                 the screen will be restored. If the user
  1201.                 presses P, the text of the box will be
  1202.                 printed on device PRN. If doclick=1, the
  1203.                 speaker will make a click sound when the
  1204.                 mouse is pressed to clear the message box.
  1205.                 If doclick=0, no sound will be made.
  1206.           If dopause=0: the box will be drawn, and grafmsg will then
  1207.                 return. doclick is ignored.
  1208.     Example:
  1209.  
  1210.     #include <string.h>
  1211.     #include <graf.h>
  1212.     #include <graphics.h>
  1213.     #include <mouse.h>
  1214.     void main()
  1215.     {
  1216.     vidmode=1;
  1217.     grafon();
  1218.     resetmouse();
  1219.     strcpy(m[0],"This is a message box");
  1220.     strcpy(m[1],"Text of the message goes here");
  1221.     grafmsg(-1,-1,1,15,0,1,1,1,0);
  1222.     closegraph();
  1223.     }
  1224.  
  1225.     --------------------------------------------------------------------------
  1226.  
  1227.     void grafrect(int x1,int y1,int x2,int y2,int color,int style,
  1228.           int thickness);
  1229.  
  1230.     Draws a rectangle. x1,y1,x2,y2 is the area covered by the rectangle.
  1231.     Color and Style are the color and fill style for the rectangle. Thickness
  1232.     is the line thickness for the edges of the rectangle. Example:
  1233.  
  1234.     #include <conio.h>
  1235.     #include <graf.h>
  1236.     #include <graphics.h>
  1237.     void main()
  1238.     {
  1239.     vidmode=1;
  1240.     grafon();
  1241.     grafrect(1000,1000,3000,2000,12,3,1);
  1242.     getch();
  1243.     closegraph();
  1244.     }
  1245.  
  1246.     --------------------------------------------------------------------------
  1247.  
  1248.     void clsstars();
  1249.  
  1250.     Clears the screen, using a stary background. Example:
  1251.  
  1252.     #include <conio.h>
  1253.     #include <graf.h>
  1254.     #include <graphics.h>
  1255.     void main()
  1256.     {
  1257.     vidmode=1;
  1258.     grafon();
  1259.     clsstars();
  1260.     getch();
  1261.     closegraph();
  1262.     }
  1263.  
  1264.     --------------------------------------------------------------------------
  1265.  
  1266.     void select(int *x, int *y,int doclick);
  1267.  
  1268.     Gets a selection using the mouse. Shows the mouse, waits for a button to
  1269.     be pressed, then hides the mouse and returns the mouse position in
  1270.     virtual coordinates. X,Y return the mouse's position when a button is
  1271.     pressed. If doclick=1, the speaker will make a click sound when the mouse
  1272.     button is pressed. If doclick=0, no click sound will be made. Example:
  1273.  
  1274.     #include <graf.h>
  1275.     #include <graphics.h>
  1276.     #include <mouse.h>
  1277.     #include <stdio.h>
  1278.     int x,y;
  1279.     void main()
  1280.     {
  1281.     vidmode=1;
  1282.     grafon();
  1283.     resetmouse();
  1284.     select(&x,&y,1);
  1285.     closegraph();
  1286.     printf("x=%d    y=%d\n",x,y);
  1287.     }
  1288.  
  1289.     --------------------------------------------------------------------------
  1290.  
  1291.     int popupmenu(int x,int y,int i,int fore,int fore2,int bak,int doclick);
  1292.  
  1293.     Does a popup menu. Menu appears, mouse appears, once an option is
  1294.     selected, mouse disappears, then menu disappears. x,y is the upper left
  1295.     corner of the menu. If x=-1, menu is centered left to right. If y=-1,
  1296.     menu is centered top to bottom.  Uses global string array m[] to hold the
  1297.     title (m[0]) and options (m[1], m[2], etc). I is the index of the last
  1298.     string used (ie for a menu that uses m[0] thru m[2], i=2). Fore and Fore2
  1299.     are the text and text shadow colors. Bak is the menu color. If Doclick=1,
  1300.     the speaker will click when the mouse button is pressed. If Doclick=0,
  1301.     no click will be made. Returns the number of the menu option selected (ie
  1302.     returns 1 if they select the 1st menu option, 2 if they select the second
  1303.     menu option, etc). Example:
  1304.  
  1305.     #include <graf.h>
  1306.     #include <graphics.h>
  1307.     #include <mouse.h>
  1308.     #include <string.h>
  1309.     int i;
  1310.     void main()
  1311.     {
  1312.     vidmode=1;
  1313.     grafon();
  1314.     resetmouse();
  1315.     /* load menu options into array */
  1316.     strcpy(m[0],"Please select...");
  1317.     strcpy(m[1],"Yes");
  1318.     strcpy(m[2],"No");
  1319.     /* call menu routine */
  1320.     i=popupmenu(-1,-1,2,15,0,1,1);
  1321.     if (i==1)
  1322.        saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"Yes selected");
  1323.     else saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,"No selected");
  1324.     nobutton();
  1325.     do
  1326.       {
  1327.       }
  1328.       while (mousebutton()==0);
  1329.     closegraph();
  1330.     }
  1331.  
  1332.     --------------------------------------------------------------------------
  1333.  
  1334.     void getstr(char *promptstr,char *returnstr,int fore,int fore2,int bak);
  1335.  
  1336.     Lets the user edit a string. Draws a dialog box, displays a prompt, then
  1337.     lets the user edit a string. Promptstr is the prompt string. Returnstr
  1338.     is the string to edit. Returnstr also returns the string edited by the
  1339.     user. Fore and Fore2 are text and text shadow colors. Bak is dialog box
  1340.     color. Example:
  1341.  
  1342.     #include <stdio.h>
  1343.     #include <graf.h>
  1344.     #include <graphics.h>
  1345.     char s[100];
  1346.     void main()
  1347.     {
  1348.     vidmode=1;
  1349.     grafon();
  1350.     strcpy(s,"");
  1351.     getstr("Enter a string...",s,15,0,1);
  1352.     closegraph();
  1353.     printf("%s\n",s);
  1354.     }
  1355.  
  1356.     --------------------------------------------------------------------------
  1357.  
  1358.     int getnum(char *promptstr,int fore,int fore2,int bak,int doclick);
  1359.  
  1360.     Gets an integer from the user, using a popup numeric keypad. Keypad
  1361.     appears with a prompt, then the mouse appears. Once the user enters
  1362.     a number and selects ok, the mouse disappears, then the keypad
  1363.     disappears. Promptstr is the prompt string. Fore and Fore2 are the text
  1364.     text shadow colors. Bak is the keypad color. If doclick=1, the speaker
  1365.     will click when a mouse button is pressed. If doclick=0, the speaker will
  1366.     not click. Returns the integer the user entered. The keypad has keys 0
  1367.     thru 9, C (clear), and Ok. Example:
  1368.  
  1369.     #include <stdio.h>
  1370.     #include <graf.h>
  1371.     #include <graphics.h>
  1372.     #include <mouse.h>
  1373.     int i;
  1374.     void main()
  1375.     {
  1376.     vidmode=1;
  1377.     grafon();
  1378.     resetmouse();
  1379.     i=getnum("Enter a number...",15,0,1,1);
  1380.     closegraph();
  1381.     printf("%d\n",i);
  1382.     }
  1383.  
  1384.     --------------------------------------------------------------------------
  1385.  
  1386.     void getfile(char *promptstr, char *searchspec, char *returnstr,int fore,
  1387.          int fore2,int bak,int doclick);
  1388.  
  1389.     Gets a filename from the user. Displays a menu listing files. The menu
  1390.     has More and Cancel options as well as filenames. Shows the mouse, and
  1391.     lets the user select from the menu. Returns the filename selected.
  1392.     Returns an empty string (ie "") for cancel. Promptstr is the prompt that
  1393.     appears as the menu title. Searchspec is the file search spec for the
  1394.     list of filenames. Wildcard characters are allowed in the search
  1395.     filespec. Returnstr returns the selected filename. Fore and Fore2 are
  1396.     text and text shadow colors. Bak is menu color. If doclick=1, speaker
  1397.     will click when a mouse button is pressed. If doclick=0 , speaker will
  1398.     not click. Example:
  1399.  
  1400.     #include <stdio.h>
  1401.     #include <graf.h>
  1402.     #include <graphics.h>
  1403.     #include <mouse.h>
  1404.     char s[100];
  1405.     void main()
  1406.     {
  1407.     vidmode=1;
  1408.     grafon();
  1409.     resetmouse();
  1410.     getfile("Select a file...","c:\\*.*",s,15,0,1,1);
  1411.     closegraph();
  1412.     printf("%s\n",s);
  1413.     }
  1414.  
  1415.     --------------------------------------------------------------------------
  1416.  
  1417.     void setborder(int i);
  1418.  
  1419.     Sets the border color. I is the color for the border. Does not work on
  1420.     all hardware. Example:
  1421.  
  1422.     #include <conio.h>
  1423.     #include <graf.h>
  1424.     #include <graphics.h>
  1425.     void main()
  1426.     {
  1427.     vidmode=1;
  1428.     grafon();
  1429.     setborder(1);
  1430.     getch();
  1431.     closegraph();
  1432.     }
  1433.  
  1434.     --------------------------------------------------------------------------
  1435.  
  1436.     int getcol(char *s,int fore,int fore2,int bak,int doclick);
  1437.  
  1438.     Gets a color from the user. Displays a menu of colors. Lets the user
  1439.     select a color with the mouse. Returns the color selected. S is the
  1440.     prompt string for the color menu. Fore and Fore2 are the text and text
  1441.     shadow colors. Bak is the menu color. If doclick=1, speaker
  1442.     will click when a mouse button is pressed. If doclick=0 , speaker will
  1443.     not click. This routine will automaticaly use either a 16 color or 256
  1444.     color menu, depending on the current video mode. Example:
  1445.  
  1446.     #include <stdio.h>
  1447.     #include <graf.h>
  1448.     #include <graphics.h>
  1449.     #include <mouse.h>
  1450.     int i;
  1451.     void main()
  1452.     {
  1453.     vidmode=1;
  1454.     grafon();
  1455.     resetmouse();
  1456.     i=getcol("Select a color...",15,0,1,1);
  1457.     closegraph();
  1458.     printf("%d\n",i);
  1459.     }
  1460.  
  1461.     --------------------------------------------------------------------------
  1462.  
  1463.     int getfill(char *s,int fore,int fore2,int bak,int color,int doclick);
  1464.  
  1465.     Gets a fillstyle from the user. Shows a menu of fill styles. Lets the
  1466.     user select a fillstyle with the mouse. Returns the fillstyle selected.
  1467.     S is the prompt string for the fillstyle menu. Fore and Fore2 are the
  1468.     text and text shadow colors. Bak is the menu color. Color is the color
  1469.     for the fillpatterns in the menu. If doclick=1, speaker will click when a
  1470.     mouse button is pressed. If doclick=0 , speaker will not click. Example:
  1471.  
  1472.     #include <stdio.h>
  1473.     #include <graf.h>
  1474.     #include <graphics.h>
  1475.     #include <mouse.h>
  1476.     int i;
  1477.     void main()
  1478.     {
  1479.     vidmode=1;
  1480.     grafon();
  1481.     resetmouse();
  1482.     i=getfill("Select a fillstyle...",15,0,1,14,1);
  1483.     closegraph();
  1484.     printf("%d\n",i);
  1485.     }
  1486.  
  1487.     --------------------------------------------------------------------------
  1488.  
  1489.     void getarea(int x1,int y1,int *x2,int *y2);
  1490.  
  1491.     Gets an area from the user. Shows the mouse, waits for the user to select
  1492.     the upper left corner of the area. Then does a rubberband box while the
  1493.     user moves to the lower right corner. When the user selects the lower
  1494.     right corner, the rubber band box disappears. The uppper left and lower
  1495.     right coordinates of the area selected are returned in x1,y1,x2,y2.
  1496.     Example:
  1497.  
  1498.     #include <conio.h>
  1499.     #include <graf.h>
  1500.     #include <graphics.h>
  1501.     #include <mouse.h>
  1502.     int x1,y1,x2,y2;
  1503.     void main()
  1504.     {
  1505.     vidmode=1;
  1506.     grafon();
  1507.     resetmouse();
  1508.     saygraf(5000,500,15,2,graffontsize,0,1,1,1,1,1,1,"Select an area...");
  1509.     getarea(x1,y1,x2,y2);
  1510.     fillgraf(x1,y1,x2,y2,14,4);
  1511.     getch();
  1512.     closegraph();
  1513.     }
  1514.  
  1515.     --------------------------------------------------------------------------
  1516.  
  1517.     int getpix(int x,int y);
  1518.  
  1519.     Gets the current color of a pixel. x,y are the pixel's coordinates.
  1520.     Returns the pixel's color. Example:
  1521.  
  1522.     #include <stdio.h>
  1523.     #include <graf.h>
  1524.     #include <graphics.h>
  1525.     int i;
  1526.     void main()
  1527.     {
  1528.     vidmode=1;
  1529.     grafon();
  1530.     i=getpix(5000,5000);
  1531.     closegraph();
  1532.     printf("%d\n",i);
  1533.     }
  1534.  
  1535.     --------------------------------------------------------------------------
  1536.  
  1537.     void fillstars(int x1,int y1,int x2,int y2);
  1538.  
  1539.     Fills an area with a stary pattern. x1,y1,x2,y2 are the area's
  1540.     coordinates. Example:
  1541.  
  1542.     #include <conio.h>
  1543.     #include <graf.h>
  1544.     #include <graphics.h>
  1545.     void main()
  1546.     {
  1547.     vidmode=1;
  1548.     grafon();
  1549.     fillstars(1000,1000,5000,5000);
  1550.     getch();
  1551.     closegraph();
  1552.     }
  1553.  
  1554.     --------------------------------------------------------------------------
  1555.  
  1556.     void grafcircle(int x,int y,int rad,int color,int style,int thickness);
  1557.  
  1558.     Draws a filled circle. x,y is the center of the circle. Rad is the
  1559.     radius. Color and Style are the fill color and fill style to use.
  1560.     Thickness is the line thickness for the edge of the circle. Example:
  1561.  
  1562.     #include <conio.h>
  1563.     #include <graf.h>
  1564.     #include <graphics.h>
  1565.     void main()
  1566.     {
  1567.     vidmode=1;
  1568.     grafon();
  1569.     grafcircle(5000,5000,1000,4,7,1);
  1570.     getch();
  1571.     closegraph();
  1572.     }
  1573.  
  1574.     --------------------------------------------------------------------------
  1575.  
  1576.     void wait4retrace(void);
  1577.  
  1578.     Waits until the beginning of the next vertical retrace. Use this to time
  1579.     your screen updates with the CRT's vertical retrace interval to reduce
  1580.     flicker. Example:
  1581.  
  1582.     #include <graf.h>
  1583.     #include <graphics.h>
  1584.     void main()
  1585.     {
  1586.     int i;
  1587.     vidmode=1;
  1588.     grafon();
  1589.     clsgraf(0,1);
  1590.     for (i=0; i<9000; i++)
  1591.     {
  1592.     waitforretrace();
  1593.     fillgraf(i,4000,i+1000,5000,15,1);
  1594.     waitforretrace();
  1595.     fillgraf(i,4000,i+1000,5000,0,1);
  1596.     }
  1597.     closegraph();
  1598.     }
  1599.  
  1600.     --------------------------------------------------------------------------
  1601.  
  1602.     void fadeout(void);
  1603.  
  1604.     Fades a 256 color palette to black. Example:
  1605.  
  1606.     #include <graf.h>
  1607.     #include <graphics.h>
  1608.     #include <math2.h>
  1609.     #include <stdlib.h>
  1610.     void main()
  1611.     {
  1612.     int i,j,k;
  1613.     randomize();
  1614.     vidmode=2;
  1615.     grafon();
  1616.     clsgraf(0,1);
  1617.     for (i=0; i<9000; i++)
  1618.     {
  1619.     j=dice(9000);
  1620.     k=dice(9000);
  1621.     fillgraf(j,k,j+1000,k+,dice(15),dice(11));
  1622.     }
  1623.     fadeout();
  1624.     closegraph();
  1625.     }
  1626.  
  1627.  
  1628.     --------------------------------------------------------------------------
  1629.  
  1630.     void fadein(struct palrec *pal);
  1631.  
  1632.     Fades in a 256 color palette from black. Example:
  1633.  
  1634.     #include <graf.h>
  1635.     #include <graphics.h>
  1636.     #include <math2.h>
  1637.     #include <stdlib.h>
  1638.     void main()
  1639.     {
  1640.     int i,j,k;
  1641.     struct palrec pal[256],pal2[256];
  1642.     randomize();
  1643.     vidmode=2;
  1644.     grafon();
  1645.     clsgraf(0,1);
  1646.     memset(pal,0,sizeof(pal));
  1647.     getallrgbpalette(pal2);
  1648.     setallrgbpalette(pal);
  1649.     for (i=0; i<9000; i++)
  1650.     {
  1651.     j=dice(9000);
  1652.     k=dice(9000);
  1653.     fillgraf(j,k,j+1000,k+,dice(15),dice(11));
  1654.     }
  1655.     fadein(pal2);
  1656.     closegraph();
  1657.     }
  1658.  
  1659.     --------------------------------------------------------------------------
  1660.  
  1661.     char getdrv(char *s, int fore, int fore2, int bak, int doclick);
  1662.  
  1663.     Lets the user select a drive from a menu. Returns the letter of the
  1664.     selected drive. Returns ' ' (a space) if user cancels. S is the prompt
  1665.     for the menu. Fore is the text color. Fore2 is the text shadow color.
  1666.     Bak is the menu color. Example:
  1667.  
  1668.     #include <graf.h>
  1669.     #include <graphics.h>
  1670.     #include <generic2.h>
  1671.     void main()
  1672.     {
  1673.     char c;
  1674.     vidmode=1;
  1675.     grafon();
  1676.     c=getdrv("Change to drive...");
  1677.     if (c != ' ') chdrv(c);
  1678.     closegraph();
  1679.     }
  1680.  
  1681.     --------------------------------------------------------------------------
  1682.  
  1683.     void refreshon(void);
  1684.  
  1685.     Turns on video refresh. Use with refreshoff() to control video refresh.
  1686.     NOTE: Turning refresh off is like turning down the monitor brightness all
  1687.     the way - I.E. the screen goes black. Example:
  1688.  
  1689.     #include <graf.h>
  1690.     #include <graphics.h>
  1691.     #include <conio.h>
  1692.     void main()
  1693.     {
  1694.     struct palrec pal[256];
  1695.     vidmod=2;
  1696.     grafon();
  1697.     getallrgbpalette2(pal);
  1698.     fadeout();
  1699.     refreshoff();
  1700.     /* draw stuff now. drawing goes faster with refresh off supposedly. */
  1701.     refreshon();
  1702.     fadein(pal);
  1703.     getch();
  1704.     closegraph();
  1705.     }
  1706.  
  1707.     --------------------------------------------------------------------------
  1708.  
  1709.     void refreshoff(void);
  1710.  
  1711.     Turns off video refresh. Use with refreshon() to control video refresh.
  1712.     NOTE: Turning refresh off is like turning down the monitor brightness all
  1713.     the way - I.E. the screen goes black. Example:
  1714.  
  1715.     #include <graf.h>
  1716.     #include <graphics.h>
  1717.     #include <conio.h>
  1718.     void main()
  1719.     {
  1720.     struct palrec pal[256];
  1721.     vidmod=2;
  1722.     grafon();
  1723.     getallrgbpalette2(pal);
  1724.     fadeout();
  1725.     refreshoff();
  1726.     /* draw stuff now. drawing goes faster with refresh off supposedly. */
  1727.     refreshon();
  1728.     fadein(pal);
  1729.     getch();
  1730.     closegraph();
  1731.     }
  1732.  
  1733.     --------------------------------------------------------------------------
  1734.  
  1735.     void getgrafsize(void *p, int *x, int *y);
  1736.  
  1737.     Gets the size of a bitmap. P points to the bitmap. The width is returned
  1738.     in X, the height in Y. The size returned is in hardware coordinates
  1739.     (pixels), not BC40LIB GRAF coordinates. Use mousex2x() and mousey2y() to
  1740.     convert to GRAF coordinates. Example:
  1741.  
  1742.     #include <graf.h>
  1743.     #include <graphics.h>
  1744.     #include <stdlib.h>
  1745.     void main()
  1746.     {
  1747.     int x,y;
  1748.     void *p;
  1749.     vidmode=2;        /* 320x200x256 */
  1750.     grafon();
  1751.     p=grafget(0,0,10000,10000);    /* get entire screen */
  1752.     getgrafsize(p,&x,&y);
  1753.     /* x is now 320. y is now 200. */
  1754.     x=mousex2x(x);
  1755.     y=mousey2y(y);
  1756.     /* x is now 10000. y is now 10000 */
  1757.     free(p);
  1758.     closegraph();
  1759.     }
  1760.  
  1761.     --------------------------------------------------------------------------
  1762.  
  1763.     void grafcopy(int x,int y,void *p,void *p2);
  1764.  
  1765.     Copies a bitmap into another bitmap. P is the source bitmap to copy. P2
  1766.     is the target bitmap to copy into. The copy is done offscreen in memory.
  1767.     The source bitmap is copied into the target bitmap beginning at
  1768.     offset x,y from the upper left corner of the target bitmap. This routine
  1769.     is currently under construction. Do not use it. It doesn't work yet. This
  1770.     description is included to keep you from wondering what it is.
  1771.  
  1772.     --------------------------------------------------------------------------
  1773.  
  1774.     void setallrgbpalette2(struct palrec *pal);
  1775.  
  1776.     Sets the computer's 256 color palette. Pal points to an array[256] of
  1777.     palrec that contains the new values for the computer's palette. Uses
  1778.     port addressing to set the palette. Appears to be slightly faster than
  1779.     setallrgbpalette() which uses a bios call to set the palette. Example:
  1780.  
  1781.     #include <conio.h>
  1782.     #include <graphics.h>
  1783.     #include <graf.h>
  1784.     struct palrec pal[256];
  1785.     void main()
  1786.     {
  1787.     grafmode=2;
  1788.     grafon();
  1789.     loadpal("test.pal",pal);   /* load test.pal from disk into PAL*/
  1790.     setallrgbpalette(pal);     /* set palette to PAL */
  1791.     getch();
  1792.     closegraph();
  1793.     }
  1794.  
  1795.     --------------------------------------------------------------------------
  1796.  
  1797.     void setrgbpalette2(int regnum,int red,int green,int blue);
  1798.  
  1799.     As BC40's setrgbpalette(). Sets a 256 color palette register using a rom
  1800.     bios interrupt call. Appears to be slightly faster than BC40's
  1801.     setrgbpalette() routine. Example:
  1802.  
  1803.     #include <graphics.h>
  1804.     #include <graf.h>
  1805.     #include <conio.h>
  1806.     void main()
  1807.     {
  1808.     int i;
  1809.     grafmode=2;
  1810.     grafon();
  1811.     clsgraf(0,1);                /* clear screen to black */
  1812.     for (i=0; i<256; i++)           /* fade in red */
  1813.     setrgbpalette2(0,i,0,0);
  1814.     getch();
  1815.     closegraph();
  1816.     }
  1817.  
  1818.     --------------------------------------------------------------------------
  1819.  
  1820.     void setrgbpalette3(int regnum,int red,int green,int blue);
  1821.  
  1822.     As BC40's setrgbpalette(). Sets a 256 color palette register using port
  1823.     Addressing. Appears to be slightly faster than setrgbpalette2() which
  1824.     uses a bios call. Example:
  1825.  
  1826.     #include <graphics.h>
  1827.     #include <graf.h>
  1828.     #include <conio.h>
  1829.     void main()
  1830.     {
  1831.     int i;
  1832.     grafmode=2;
  1833.     grafon();
  1834.     clsgraf(0,1);                     /* clear screen to black */
  1835.     for (i=0; i<256; i++)               /* fade in purple */
  1836.     setrgbpalette2(0,i,0,i);
  1837.     getch();
  1838.     closegraph();
  1839.     }
  1840.  
  1841. ==============================================================================
  1842.  
  1843. Joystick.c:
  1844.     This library provides joystick support routines. Variables and routines
  1845.     are as follows:
  1846.  
  1847.     --------------------------------------------------------------------------
  1848.  
  1849.     extern int hasstick;
  1850.  
  1851.     Boolean variable set by detectstick(). Hasstick=1 means a game port is
  1852.     connected. A joystick may or may not be connected to the game port.
  1853.     Detectstick can't tell if there's a joystick, only a game port.
  1854.     Hasstick=0 means no game port found, therefore no joystick. Example:
  1855.  
  1856.     #include <stdio.h>
  1857.     #include <joystick.h>
  1858.     void main()
  1859.     {
  1860.     detectstick();
  1861.     if (hasstick) printf("Game port found\n");
  1862.     else printf("No game port found\n");
  1863.     }
  1864.  
  1865.     --------------------------------------------------------------------------
  1866.  
  1867.     void getstik(int *x, int *y, int *b1, int *b2);
  1868.  
  1869.     Gets the current joystick status. Returns joystick information in x,y,b1,
  1870.     and b2. X and y are numbers returned by the stick that indicate position.
  1871.     The minimum and maximum values returned for x and y depend on computer
  1872.     speed, and will vary from machine to machine. For x, the minimum value is
  1873.     all the way left. For y, the minimum value is all the way forward.
  1874.     Because the minimum and maximum values for x and y vary with machine, you
  1875.     will need to write a joystick calibration routine to determine the
  1876.     minimum and maximum x and y values returned. B1 and B2 return the status
  1877.     of the buttons. B1 is for button #1, and B2 is for button #2. A value of
  1878.     1 indicates pressed, 0 means not pressed. Example:
  1879.  
  1880.     #include <stdio.h>
  1881.     #include <joystick.h>
  1882.     int x,y,b1,b2;
  1883.     void main()
  1884.     {
  1885.     printf("move stick to upper left and press button 1...\n");
  1886.     do
  1887.       {
  1888.       getstik(&x,&y,*b1,&b2);
  1889.       }
  1890.       while (b1==0);
  1891.     printf("minimum x value is %d\n",x);
  1892.     printf("minimum y value is %d\n",y);
  1893.     }
  1894.  
  1895.     --------------------------------------------------------------------------
  1896.  
  1897.     void nostikbutton();
  1898.  
  1899.     Waits until no joystick buttons are being pressed. Example:
  1900.  
  1901.     #include <stdio.h>
  1902.     #include <joystick.h>
  1903.     int x,y,b1,b2;
  1904.     void main()
  1905.     {
  1906.     printf("press joystick button 1...\n");
  1907.     do
  1908.       {
  1909.       getstik(&x,&y,*b1,&b2);
  1910.       }
  1911.       while (b1==0);
  1912.     printf("button 1 pressed\n");
  1913.     nostikbutton();
  1914.     printf("button 1 released\n");
  1915.     }
  1916.  
  1917.     --------------------------------------------------------------------------
  1918.  
  1919.     void detectstick();
  1920.  
  1921.     Checks for existance of a game port. Sets the global variable Hasstick to
  1922.     1 if a game port is found, else sets hasstick to 0. Example:
  1923.  
  1924.     #include <stdio.h>
  1925.     #include <joystick.h>
  1926.     void main()
  1927.     {
  1928.     detectstick();
  1929.     if (hasstick) printf("Game port found\n");
  1930.     else printf("No game port found\n");
  1931.     }
  1932.  
  1933. ==============================================================================
  1934.  
  1935. Keyboard.c:
  1936.     This library provides interrupt driven keyboard input. It can be used for
  1937.     programs such as keyboard driven realtime simulator games. It replaces
  1938.     the keyboard interrupt handler with a routine that updates an array that
  1939.     stores the current state (pressed or not pressed) of the keys. Once the
  1940.     new handler is installed, the kepressed() function can be used to get the
  1941.     current state (pressed or not pressed) of a key. Routines are as follows:
  1942.  
  1943.     --------------------------------------------------------------------------
  1944.  
  1945.     void startkeyboard();
  1946.  
  1947.     Clears keys array, saves old interrupt 9 (keyboard) handler address,
  1948.     installs new interrupt 9 handler. The new handler updates an array that
  1949.     tracks the state (pressed or not pressed) of the keys, and then calls the
  1950.     old int 9 handler. Call once before accessing keys array via keypressed().
  1951.     Example:
  1952.  
  1953.     #include <keyboard.h>
  1954.     #include <stdio.h>
  1955.     void main()
  1956.     {
  1957.     startkeyboard();
  1958.     do
  1959.       {
  1960.       printf("Esc not pressed\n");
  1961.       }
  1962.       while (! keypressed(0));
  1963.     do
  1964.       {
  1965.       printf("Esc is pressed\n");
  1966.       }
  1967.       while (keypressed(0));
  1968.     stopkeyboard();
  1969.     }
  1970.  
  1971.  
  1972.     --------------------------------------------------------------------------
  1973.  
  1974.     int keypressed(int i);
  1975.  
  1976.     Returns the state of a key. I is the scancode of the key. Returns 1 if
  1977.     the key is being pressed, else returns 0. Example:
  1978.  
  1979.     #include <keyboard.h>
  1980.     #include <stdio.h>
  1981.     void main()
  1982.     {
  1983.     startkeyboard();
  1984.     do
  1985.       {
  1986.       printf("Esc not pressed\n");
  1987.       }
  1988.       while (! keypressed(0));
  1989.     do
  1990.       {
  1991.       printf("Esc is pressed\n");
  1992.       }
  1993.       while (keypressed(0));
  1994.     stopkeyboard();
  1995.     }
  1996.  
  1997.  
  1998.     --------------------------------------------------------------------------
  1999.  
  2000.     void stopkeyboard();
  2001.  
  2002.     Restores the old interrupt 9 handler. Call this routine once when you're
  2003.     done accessing keys array. Example:
  2004.  
  2005.     #include <keyboard.h>
  2006.     #include <stdio.h>
  2007.     void main()
  2008.     {
  2009.     startkeyboard();
  2010.     do
  2011.       {
  2012.       printf("Esc not pressed\n");
  2013.       }
  2014.       while (! keypressed(0));
  2015.     do
  2016.       {
  2017.       printf("Esc is pressed\n");
  2018.       }
  2019.       while (keypressed(0));
  2020.     stopkeyboard();
  2021.     }
  2022.  
  2023. ==============================================================================
  2024.  
  2025. Math2.c:
  2026.     This library provides various math routines. Data structures and routines
  2027.     are as follows:
  2028.  
  2029.     --------------------------------------------------------------------------
  2030.  
  2031.     extern float sinof[360],cosof[360];
  2032.  
  2033.     These arrays are lookup tables that hold the values of the sins and
  2034.     cosines of angles from 0 to 359 degrees. For example sinof[0] holds the
  2035.     sin of 0 degrees. Cosof[0] holds the cosine of 0 degrees. They must be
  2036.     initialized by a call to inittrigtables(). After that you may access them
  2037.     instead of calling sin() and cos(). Accessing the lookup tables runs MUCH
  2038.     faster than calling sin() or cos(). Example:
  2039.  
  2040.     #include <math2.h>
  2041.     #include <stdio.h>
  2042.     int i;
  2043.     void main()
  2044.     {
  2045.     inittrigtables();
  2046.     for (i=0; i<360; i++)
  2047.     printf("i=%d  sin(i)=%f  cos(i)=%f\n",i,sinof[i],cosof[i]);
  2048.     }
  2049.  
  2050.     --------------------------------------------------------------------------
  2051.  
  2052.     int round(float f);
  2053.  
  2054.     Returns the rounded off value of a number. The number is rounded to the
  2055.     nearest integer. Example:
  2056.  
  2057.     #include <math2.h>
  2058.     #include <stdio.h>
  2059.     int i;
  2060.     void main()
  2061.     {
  2062.     i=round(3.141);
  2063.     printf("Round(3.141)=%d\n",i);
  2064.     }
  2065.  
  2066.     --------------------------------------------------------------------------
  2067.  
  2068.     int headingto(long x1, long y1, long x2, long y2);
  2069.  
  2070.     Returns the compass heading (0 to 359 degrees) from point x1,y1 to point
  2071.     x2,y2. The points are points on a right cartiesan plane coordinate
  2072.     system. Example:
  2073.  
  2074.     #include <math2.h>
  2075.     #include <stdio.h>
  2076.     int i;
  2077.     void main()
  2078.     {
  2079.     i=headingto(1,1,2,2);   /* i is 45 degrees */
  2080.     printf("heading from 1,1 to 2,2 is %d degrees\n",i);
  2081.     }
  2082.  
  2083.     --------------------------------------------------------------------------
  2084.  
  2085.     int markvalue(long x1, long y1, long z1, long x2, long y2, long z2);
  2086.  
  2087.     Returns the spherical coordinate system second angle (rho - angle of
  2088.     inclination) from the point x1,y1,z1 to the point x2,y2,z2. The points
  2089.     are in right cartesian coordinates. For the value returned, 0 is
  2090.     horizontal, 90 is up, -90 is down 180/-180 is upsidedown & opposite
  2091.     direction. Example:
  2092.  
  2093.     #include <math2.h>
  2094.     #include <stdio.h>
  2095.     int i;
  2096.     void main()
  2097.     {
  2098.     i=markvalue(1,1,1,2,2,2);   /* i is 45 degrees */
  2099.     printf("markvalue from 1,1,1 to 2,2,2 is %d degrees\n",i);
  2100.     }
  2101.  
  2102.     --------------------------------------------------------------------------
  2103.  
  2104.     long dist3d(long x1, long y1, long z1, long x2, long y2, long z2);
  2105.  
  2106.     Returns the 3 dimentional distance from point x1,y1,z1 to point x2,y2,z2.
  2107.     the points are in right cartesian coodinates. Example:
  2108.  
  2109.     #include <math2.h>
  2110.     #include <stdio.h>
  2111.     long l;
  2112.     void main()
  2113.     {
  2114.     l=dist3d(1,1,1,20,20,20);
  2115.     printf("distance from 1,1,1 to 20,20,20 is %d\n",l);
  2116.     }
  2117.  
  2118.     --------------------------------------------------------------------------
  2119.  
  2120.     void i2s(long i,char *s);
  2121.  
  2122.     Converts an integer to a string. I is the integer to convert. S is the
  2123.     string to return the result in. Example:
  2124.  
  2125.     #include <math2.h>
  2126.     #include <stdio.h>
  2127.     int i;
  2128.     char s[100];
  2129.     void main()
  2130.     {
  2131.     i=45;
  2132.     i2s(i,s);
  2133.     printf("i = %s\n",s);
  2134.     }
  2135.  
  2136.     --------------------------------------------------------------------------
  2137.  
  2138.     void l2s(long i,char *s);
  2139.  
  2140.     Converts a long integer to a string. I is the integer to convert. S is the
  2141.     string to return the result in. Example:
  2142.  
  2143.     #include <math2.h>
  2144.     #include <stdio.h>
  2145.     int i;
  2146.     char s[100];
  2147.     void main()
  2148.     {
  2149.     i=45;
  2150.     i2s(i,s);
  2151.     printf("i = %s\n",s);
  2152.     }
  2153.  
  2154.     --------------------------------------------------------------------------
  2155.  
  2156.     void f2s(float f,char *s);
  2157.  
  2158.     Converts a float to a string. F is the float to convert. S is the
  2159.     string to return the result in. The result will have 20 digits. Example:
  2160.  
  2161.     #include <math2.h>
  2162.     #include <stdio.h>
  2163.     float i;
  2164.     char s[100];
  2165.     void main()
  2166.     {
  2167.     i=1.0;
  2168.     f2s(i,s);
  2169.     printf("i = %s\n",s);   /* prints "i = 1.0000000000000000000"   */
  2170.     }
  2171.  
  2172.     --------------------------------------------------------------------------
  2173.  
  2174.     void f2s2(float f,char *s);
  2175.  
  2176.     Converts a float to a string. F is the float to convert. S is the
  2177.     string to return the result in. The result will have 2 decimal places.
  2178.     Example:
  2179.  
  2180.     #include <math2.h>
  2181.     #include <stdio.h>
  2182.     float i;
  2183.     char s[100];
  2184.     void main()
  2185.     {
  2186.     i=1.0;
  2187.     f2s(i,s);
  2188.     printf("i = %s\n",s);   /* prints "i = 1.00"   */
  2189.     }
  2190.  
  2191.     --------------------------------------------------------------------------
  2192.  
  2193.     int s2i(char *s);
  2194.  
  2195.     Converts a string to an integer. Returns the integer value of string S.
  2196.     Example:
  2197.  
  2198.     #include <math2.h>
  2199.     #include <stdio.h>
  2200.     #include <string.h>
  2201.     int i;
  2202.     char s[100];
  2203.     void main()
  2204.     {
  2205.     strcpy(s,"100");
  2206.     i=s2i(s);
  2207.     printf("s = %d\n",i);
  2208.     }
  2209.  
  2210.     --------------------------------------------------------------------------
  2211.  
  2212.     long s2l(char *s);
  2213.  
  2214.     Converts a string to a long integer. Returns the integer value of string
  2215.     S. Example:
  2216.  
  2217.     #include <math2.h>
  2218.     #include <stdio.h>
  2219.     #include <string.h>
  2220.     long i;
  2221.     char s[100];
  2222.     void main()
  2223.     {
  2224.     strcpy(s,"100000");
  2225.     i=s2l(s);
  2226.     printf("s = %d\n",i);
  2227.     }
  2228.  
  2229.     --------------------------------------------------------------------------
  2230.  
  2231.     int isin(int x, int y, int x1, int y1, int x2, int y2);
  2232.  
  2233.     Returns 1 if point x,y is in the area x1,y1,x2,y2. Otherwise returns 0.
  2234.     Useful for seeing if the user clicked in an area, etc. Example:
  2235.  
  2236.     #include <math2.h>
  2237.     #include <graf.h>
  2238.     #include <graphics.h>
  2239.     #include <mouse.h>
  2240.     int x,y;
  2241.     void main()
  2242.     {
  2243.     vidmode=1;
  2244.     grafon();
  2245.     resetmouse();
  2246.     grafrect(1000,1000,2000,2000,15,0,1);
  2247.     saygraf(5000,5000,15,2,graffontsize,0,1,1,1,1,1,1,
  2248.                          "Click in rectangle to quit");
  2249.     do
  2250.       {
  2251.       select(x,y,1);
  2252.       }
  2253.       while (! isin(x,y,1000,1000,2000,2000));
  2254.     closegraph();
  2255.     }
  2256.  
  2257.     --------------------------------------------------------------------------
  2258.  
  2259.     int dice(int i);
  2260.  
  2261.     Returns the roll of a I sided die. Ie: dice(6) returns the roll of a 6
  2262.     sided die, and dice(100) retruns the roll of a 100 sided die. You must
  2263.     call the standard routine randomize() once at program start to initialize
  2264.     the random number generator before you can call dice(). Example:
  2265.  
  2266.     #include <stdlib.h>
  2267.     #include <math2.h>
  2268.     #include <stdio.h>
  2269.     void main()
  2270.     {
  2271.     randomize();
  2272.     printf("%d\n",dice(6));   /* prints random number 1 to 6 */
  2273.     }
  2274.  
  2275.     --------------------------------------------------------------------------
  2276.  
  2277.     void ulim(int *i, int j);
  2278.  
  2279.     Upper limits i to a value no greater than j. IE: if i>j, i=j. Example:
  2280.  
  2281.     #include <math2.h>
  2282.     #include <stdio.h>
  2283.     int i;
  2284.     void main()
  2285.     {
  2286.     i=10;
  2287.     ulim(&i,5);
  2288.     printf("%d\n",i);   /* prints 5 */
  2289.     i=10;
  2290.     ulim(&i,20);
  2291.     printf("%d\n",i);   /* prints 10 */
  2292.     }
  2293.  
  2294.     --------------------------------------------------------------------------
  2295.  
  2296.     void normalize(int *i);
  2297.  
  2298.     Converts a degree value i to its equivalent value in the range 0 to 359
  2299.     degrees. Example:
  2300.  
  2301.     #include <math2.h>
  2302.     #include <stdio.h>
  2303.     int i;
  2304.     void main()
  2305.     {
  2306.     i=35;
  2307.     normalize(&i);
  2308.     printf("%d\n",i);   /* prints 35 */
  2309.     i=-45;
  2310.     normalize(&i);
  2311.     printf("%d\n",i);   /* prints 315 */
  2312.     i=360;
  2313.     normalize(&i);
  2314.     printf("%d\n",i);   /* prints 0 */
  2315.     }
  2316.  
  2317.     --------------------------------------------------------------------------
  2318.  
  2319.     void llim(int *i, int j);
  2320.  
  2321.     Lower limits i to a value no less than j. IE: if i<j i=j. Example:
  2322.  
  2323.     #include <math2.h>
  2324.     #include <stdio.h>
  2325.     int i;
  2326.     void main()
  2327.     {
  2328.     i=10;
  2329.     llim(&i,5);
  2330.     printf("%d\n",i);   /* prints 10 */
  2331.     i=10;
  2332.     llim(&i,20);
  2333.     printf("%d\n",i);   /* prints 20 */
  2334.     }
  2335.  
  2336.     --------------------------------------------------------------------------
  2337.  
  2338.     void inittrigtables();
  2339.  
  2340.     Initializes the sinof[] and cosof[] lookup table arrays. Call once before
  2341.     using the sinof[] and cosof[] lookup table arrays. Example:
  2342.  
  2343.     #include <math2.h>
  2344.     #include <stdio.h>
  2345.     int i;
  2346.     void main()
  2347.     {
  2348.     inittrigtables();
  2349.     for (i=0; i<360; i++)
  2350.     printf("i=%d  sin(i)=%f  cos(i)=%f\n",i,sinof[i],cosof[i]);
  2351.     }
  2352.  
  2353.     --------------------------------------------------------------------------
  2354.  
  2355.     long dist2d(long x1, long y1, long x2, long y2);
  2356.  
  2357.     Returns the 2 dimentional distance from point x1,y1 to point x2,y2.
  2358.     the points are in right cartesian coodinates. Example:
  2359.  
  2360.     #include <math2.h>
  2361.     #include <stdio.h>
  2362.     long l;
  2363.     void main()
  2364.     {
  2365.     l=dist2d(1,1,20,20);
  2366.     printf("distance from 1,1 to 20,20 is %d\n",l);
  2367.     }
  2368.  
  2369. ==============================================================================
  2370.  
  2371. Mouse.c:
  2372.     This library provides routines for using a Microsoft compatable mouse.
  2373.     Data structures and routines are as follows:
  2374.  
  2375.     --------------------------------------------------------------------------
  2376.  
  2377.     extern int hasmouse;
  2378.  
  2379.     Global boolean. If hasmouse=1, then they have a mouse. If hasmouse=0 they
  2380.     don't. This variable is set by the resetmouse() routine. Example:
  2381.  
  2382.     #include <stdio.h>
  2383.     #include <mouse.h>
  2384.     void main()
  2385.     {
  2386.     resetmouse();
  2387.     if (hasmouse) printf("mouse found\n");
  2388.     else printf("mouse not found\n");
  2389.     }
  2390.  
  2391.     --------------------------------------------------------------------------
  2392.  
  2393.     void resetmouse();
  2394.  
  2395.     Resets the mouse. Call once at program start before using the mouse.
  2396.     Sets the hasmouse variable. Example:
  2397.  
  2398.     #include <stdio.h>
  2399.     #include <mouse.h>
  2400.     void main()
  2401.     {
  2402.     resetmouse();
  2403.     if (hasmouse) printf("mouse found\n");
  2404.     else printf("mouse not found\n");
  2405.     }
  2406.  
  2407.     --------------------------------------------------------------------------
  2408.  
  2409.     int mousebutton();
  2410.  
  2411.     Returns the current mouse button state. The values returned are:
  2412.     0=no buttons pressed.
  2413.     1=left button pressed.
  2414.     2=right button pressed.
  2415.     3=left and right buttons pressed.
  2416.     4=middle button pressed.
  2417.     5=middle and left buttons pressed.
  2418.     6=middle and right buttons pressed.
  2419.     7=all three buttons pressed.
  2420.     Example:
  2421.  
  2422.     #include <stdio.h>
  2423.     #include <mouse.h>
  2424.     int i;
  2425.     void main()
  2426.     {
  2427.     resetmouse();
  2428.     do
  2429.       {
  2430.       i=mousebutton();
  2431.       if (i==1) printf("left button pressed\n");
  2432.       }
  2433.       while (i != 2);
  2434.     }
  2435.  
  2436.     --------------------------------------------------------------------------
  2437.  
  2438.     void nobutton();
  2439.  
  2440.     Waits until no mouse buttons are being pressed. Example:
  2441.  
  2442.     #include <stdio.h>
  2443.     #include <mouse.h>
  2444.     void main()
  2445.     {
  2446.     resetmouse();
  2447.     printf("press and hold left mouse button\n");
  2448.     do
  2449.       {
  2450.       }
  2451.       while (mousebutton() != 1);
  2452.     printf("release all mouse buttons\n");
  2453.     nobutton();
  2454.     }
  2455.  
  2456.     --------------------------------------------------------------------------
  2457.  
  2458.     void showmouse();
  2459.  
  2460.     Makes the mouse cursor appear on the screen. Example:
  2461.  
  2462.     #include <stdio.h>
  2463.     #include <mouse.h>
  2464.     void main()
  2465.     {
  2466.     resetmouse();
  2467.     showmouse();
  2468.     do
  2469.       {
  2470.       }
  2471.       while (! mousebutton());
  2472.     hidemouse();
  2473.     }
  2474.  
  2475.     --------------------------------------------------------------------------
  2476.  
  2477.     void hidemouse();
  2478.  
  2479.     Makes the mouse cursor disappear. Example:
  2480.  
  2481.     #include <stdio.h>
  2482.     #include <mouse.h>
  2483.     void main()
  2484.     {
  2485.     resetmouse();
  2486.     showmouse();
  2487.     do
  2488.       {
  2489.       }
  2490.       while (! mousebutton());
  2491.     hidemouse();
  2492.     nobutton();
  2493.     do
  2494.       {
  2495.       }
  2496.       while (! mousebutton());
  2497.     showmouse();
  2498.     nobutton();
  2499.     do
  2500.       {
  2501.       }
  2502.       while (! mousebutton());
  2503.     hidemouse();
  2504.     }
  2505.  
  2506.     --------------------------------------------------------------------------
  2507.  
  2508.     void getmouse(int *x,int *y,int *b);
  2509.  
  2510.     Gets the current state of the mouse. x,y is its position on screen in
  2511.     hardware video coordinates. B is the button state. Values for B are the
  2512.     same as in the mousebutton() routine. Example:
  2513.  
  2514.     #include <stdio.h>
  2515.     #include <mouse.h>
  2516.     int x,y,b;
  2517.     void main()
  2518.     {
  2519.     resetmouse();
  2520.     showmouse();
  2521.     do
  2522.       {
  2523.       getmouse(&x,&y,&b);
  2524.       }
  2525.       while (b==0);
  2526.     hidemouse();
  2527.     }
  2528.  
  2529.     --------------------------------------------------------------------------
  2530.  
  2531.     void putmouse(int x,int y);
  2532.  
  2533.     Moves the mouse to point x,y (video hardware coordinates). Example:
  2534.  
  2535.     #include <stdio.h>
  2536.     #include <mouse.h>
  2537.     int x,y,b;
  2538.     void main()
  2539.     {
  2540.     resetmouse();
  2541.     showmouse();                     /* show mouse */
  2542.     do                               /* wait for click */
  2543.       {
  2544.       getmouse(&x,&y,&b);
  2545.       }
  2546.       while (b==0);
  2547.     hidemouse();                    /* hide mouse */
  2548.     putmouse(0,0);         /* move mouse to upper left corner of screen */
  2549.     showmouse();                   /* show mouse */
  2550.     nobutton();                  /* wait for no mouse buttons */
  2551.     do                              /* wait for click */
  2552.       {
  2553.       getmouse(&x,&y,&b);
  2554.       }
  2555.       while (b==0);
  2556.     hidemouse();                      /* hide mouse */
  2557.     }
  2558.  
  2559. ==============================================================================
  2560.  
  2561. Timer.c:
  2562.     This library provides routines for accurate timing delays. The routines
  2563.     run off the DOS system clock. This gives you delays that are the same
  2564.     on different PCs. These routines work well for timing screen updates to
  2565.     soundcard music. Routines are as follows:
  2566.  
  2567.     --------------------------------------------------------------------------
  2568.  
  2569.     void starttimer();
  2570.  
  2571.     Initializes the timer to zero. Call this routine to begin timing. Example:
  2572.  
  2573.     #include <timer.h>
  2574.     #include <stdio.h>
  2575.     void main()
  2576.     {
  2577.     int i;
  2578.     long l;
  2579.     starttimer();
  2580.     for (i=0; i<1000; i++)
  2581.     {
  2582.     }
  2583.     l=elapsedtime();
  2584.     printf("%d\n",l);    /* print # of millisecs to run the loop */
  2585.     }
  2586.  
  2587.     --------------------------------------------------------------------------
  2588.  
  2589.     long elapsedtime(void);
  2590.  
  2591.     Returns the elapsed time (in milliseconds) since starttimer() was called.
  2592.     Example:
  2593.  
  2594.     #include <timer.h>
  2595.     #include <stdio.h>
  2596.     void main()
  2597.     {
  2598.     int i;
  2599.     long l;
  2600.     starttimer();
  2601.     for (i=0; i<1000; i++)
  2602.     {
  2603.     }
  2604.     l=elapsedtime();
  2605.     printf("%d\n",l);    /* print # of millisecs to run the loop */
  2606.     }
  2607.  
  2608. ==============================================================================
  2609.  
  2610. Help.c:
  2611.     This library provides you with a help file viewer. The viewer runs in
  2612.     graphics, and has search and print capabilites. The viewer can display
  2613.     any ascii file. The help library contains one routine:
  2614.  
  2615.     --------------------------------------------------------------------------
  2616.  
  2617.     void showhelp(char *s2);
  2618.  
  2619.     Shows an ascii file. S2 is the name of the file to show. Example:
  2620.  
  2621.     #include <graf.h>
  2622.     #include <mouse.h>
  2623.     #include <graphics.h>
  2624.     void main()
  2625.     {
  2626.     vidmode=1;
  2627.     grafon();
  2628.     resetmouse();
  2629.     showhelp("c:\\autoexec.bat");
  2630.     closegraph();
  2631.     }
  2632.  
  2633. ==============================================================================
  2634.  
  2635. Getfile.c:
  2636.     This library provides a file selection dialog box. The library consists
  2637.     of one routine getfile() which shows a dialog box and lets the user select
  2638.     a file.
  2639.  
  2640.     --------------------------------------------------------------------------
  2641.  
  2642.     void getfile(char *promptstr, char *searchspec, char *returnstr,
  2643.           int forecolor,int forecolor2,int bakcolor,int doaclick);
  2644.  
  2645.     Shows a dialog box that lets the user select a file. Promptstr is the
  2646.     prompt to display (such as "Load file..."). Searchspec is the filespec
  2647.     used for showing files (such as "*.*" or "*.dat" etc). Returnstr is the
  2648.     string that the name of the selected file is returned in. Forecolor is
  2649.     the text color, forecolor2 is the text shadow color, and bakcolor is the
  2650.     box color. If doaclick=1, a click will be made when the user clicks on
  2651.     a selection. No click will be made if doclick=0. Returns the complete
  2652.     filename (drive, directory, filename, and extension). Saves and restores
  2653.     the screen behind the box. Returns "" if user cancels. User can change
  2654.     drives, directories, and the searchspec. User can select a file, enter
  2655.     a filename, or cancel. Shows alpabetized listings of files and subdirs.
  2656.     User can scroll and page through subdir and file lists. Sorts lists in
  2657.     memory for speed. Can handle up to 100 subdirs per directory, and 1000
  2658.     files per directory. Example:
  2659.  
  2660.     #include <graf.h>
  2661.     #include <graphics.h>
  2662.     #include <getfile.h>
  2663.     #include <edit.h>
  2664.     #include <string.h>
  2665.     #include <mouse.h>
  2666.     void main()
  2667.     {
  2668.     char s[100];
  2669.     vidmode=1;
  2670.     grafon();
  2671.     resetmouse();
  2672.     getfile("Select file to edit...","*.*",s,15,0,7,1);
  2673.     if (strcmp(s,"") !=0) editfile(s,15,0,7,1);
  2674.     closegraph();
  2675.     }
  2676.  
  2677. ==============================================================================
  2678.  
  2679.  
  2680.  
  2681.